import { GCellRenderer } from "../../../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../../../common/ObjCreate";
import { Language } from "../../../../../../extend/language/Language";
import { UnionInfoContentSpite } from "./UnionInfoContentSpite";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { ImagesConst } from "../../../../resource/ImagesConst";
import { LoaderHelp } from "../../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../../resource/ResFileConst";
import { SEntityId } from "../../../../../../Message/Public/SEntityId";
import { Cache } from "../../../../cache/Cache";
import { EntityUtil } from "../../../../scene/layer/utils/EntityUtil";
import { UnionInviteInfo } from "../../info/UnionInviteInfo";
import { DominionId } from "../../../../../../Message/Public/DominionId";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { MsgManager } from "../../../../manager/MsgManager";
import { GlobalClass } from "../../../../../../com/mui/core/GlobalClass";
import { SDominionBattlePreview } from "../../../../../../Message/Public/SDominionBattlePreview";
import { GButton } from "../../../../../../com/mui/controls/GButton";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
//class UnionInfoCellRender
    
    export  class UnionInfoCellRender extends GCellRenderer
    {
        constructor()
        {
            super();
            return;
        }

        protected /* override */ configUI(): void
        {
            super.configUI();
            this._redCityBmp = new Object /* flash.display.Bitmap */();
            this._redCityBmp.x = 20;
            this._redCityBmp.y = 0;
            this.addChild(this._redCityBmp);
            this._vsBmp = new Object /* flash.display.Bitmap */();
            this._vsBmp.x = 406;
            this._vsBmp.y = 35;
            this.addChild(this._vsBmp);
            this._inviteBtn = ObjCreate.createGButton(Language.getString(60869), 704, 4, 70, 25, this);
            this._inviteBtn.drawNow();
            this._inviteBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            this._leftUnion = new UnionInfoContentSpite();
            this.addChild(this._leftUnion);
            this._leftUnion.x = 263;
            this._leftUnion.y = 25;
            this._leftUnion.updateInfo(null, true);
            this._rightUnion = new UnionInfoContentSpite();
            this.addChild(this._rightUnion);
            this._rightUnion.x = 600;
            this._rightUnion.y = 25;
            this._rightUnion.updateInfo(null);
            this._cityNameTxt = ObjCreate.createGTextField("", 40, 78, 120, 20, this, GlobalStyle.textFormat5);
            this._cityNameTxt.autoSize = "left";
            ObjCreate.createBg(0, 96, 790, 2, this, ImagesConst.SplitLine);
            LoaderHelp.addResCallBack(ResFileConst.dominionWarBeacon, this.onLoaded);
            return;
        }

        /* internal  */get entityId(): SEntityId
        {
            return Cache.instance.role.entityInfo.entityId;
        }

        protected onClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc2=false;
            var loc3=false;
            var loc4=null;
            var loc5=undefined;
            var loc1=[];
            if (this.info) 
            {
                loc2 = EntityUtil.isSameServerByProxyAndServer(this.info.mainActId.proxyId, this.info.mainActId.serverId);
                loc3 = EntityUtil.isSameServerByProxyAndServer(this.info.mainDefId.proxyId, this.info.mainDefId.serverId);
                if (loc2 || loc3) 
                {
                    var loc6=0;
                    var loc7=this.info.dominionIds;
                    for (loc5 in loc7) 
                    {
                        (loc4 = new UnionInviteInfo()).domId = loc5 as DominionId;
                        loc4.cambat = this.info.dominionIds[loc5];
                        loc4.x = this.info.x;
                        loc4.y = this.info.y;
                        loc1.push(loc4);
                    }
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ToOpenInviteUI, {"type": 1, "data": loc1}));
                }
                else 
                {
                    MsgManager.showRollTipsMsg(Language.getString(90665));
                }
            }
            return;
        }

        /* internal  */onLoaded(): void
        {
            this._redCityBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.DwbCity_auctionCityIco);
            this._vsBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.DomWarBea_VSimg);
            return;
        }

        /* internal  */get info(): SDominionBattlePreview
        {
            return this._data as SDominionBattlePreview;
        }

        public /* override */ set data(arg1: Object)
        {
            if (arg1 == null) 
            {
                return;
            }
            super.data = arg1;
            if (this.info) 
            {
                this._cityNameTxt.text = this.info.name;
                this._leftUnion.updateInfo({"mainId": this.info.mainActId, "assistIds": this.info.assistActIds, "combat": this.info.actCombat}, true);
                this._rightUnion.updateInfo({"mainId": this.info.mainDefId, "assistIds": this.info.assistDefIds, "combat": this.info.defCombat});
            }
            return;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            super.dispose(arg1);
            this._inviteBtn.removeEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            return;
        }

        /* internal */ /* var */_leftUnion: UnionInfoContentSpite;

        /* internal */ /* var */_rightUnion: UnionInfoContentSpite;

        /* internal */ /* var */_inviteBtn: GButton;

        /* internal */ /* var */_vsBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_redCityBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_cityNameTxt: GTextFiled;
    }
